package com.game.astd.web;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.logicalcobwebs.proxool.configuration.PropertyConfigurator;

public class LoginUnit
{

	/**
	 * 登录
	 * 
	 * @param name
	 * @param password
	 * @return
	 */
	public static Map<String, String> login(String name, String password)
	{
		List<Map<String, String>> dList = DBUtil.executeQuery("select * from u_user where username=?", new String[] { name });
		if (dList.isEmpty())
		{
			return null;
		} else
		{
			String md5P = CryptUtil.encode(password);
			for (Map<String, String> d : dList)
			{
				if (d.get("username").equalsIgnoreCase(name))
				{
					String p = d.get("password");
					if (p.equals(md5P))
					{
						return d;
					} else
					{
						return null;
					}
				}
			}
		}
		return null;
	}

	public static int addUser(String username, String dl,String area,String game_user, String password)
	{
		int size = DBUtil.executeUpdate("insert into u_game_user(username,game_dl,game_area,game_user,game_password)values(?,?,?,?,?)", new String[] { username,dl,area,game_user,CryptUtil.encode(password)});
		return size;
	}
	

	public static List<Map<String, String>> getGameAccount(String username)
	{
		List<Map<String, String>> dList = DBUtil.executeQuery("select * from u_game_user where username=?", new String[] { username });
		return dList;
	}



	public static boolean getPrivage(String username, String dl, String area, String fname, String password)
	{
		return true;
	}

	public static void main(String[] args)
	{
	}
}
